package wq.test.spring.cloud.ui.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

import wq.test.spring.cloud.ui.model.Greeting;


@Service
public class GreetingService {
//	@Autowired
	RestTemplate restTemplate;

	@HystrixCommand(fallbackMethod = "fallbackSearchAll")

	public List<Greeting> searchAll() {
		return restTemplate.getForObject("http://greeting-service/greeting/list", List.class);
	}

	private List<Greeting> fallbackSearchAll() {
		System.out.println("HystrixCommand fallbackMethod handle!");
		List<Greeting> ls = new ArrayList<Greeting>();
		Greeting user = new Greeting();
		user.setName("TestHystrix");
		ls.add(user);
		return ls;
	}

}
